package com.sanley.piss.web.controller;


import com.sanley.piss.mapper.WorkExperienceMapper;
import com.sanley.piss.model.exceptionUtil.json.JsonResult;
import com.sanley.piss.model.po.WorkExperience;
import com.sanley.piss.web.service.mapper.IWorkExperienceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * Create By  on 2021/3/13.
 *
 * @author 张凯大天才
 */
@Api(value = "工作经历表controller", tags = "工作经历表操作接口")
@RestController
@RequestMapping("work")
public class WorkExperienceController {
    @Autowired
    private IWorkExperienceService service;
    @Autowired
    private WorkExperienceMapper mapper;

    @ApiOperation(value = "根据员工基本信息表ID 增加一条数据")
    @RequestMapping(value = "/{userId}/insert", method = RequestMethod.PUT)
    public JsonResult insert(@Valid WorkExperience workExperience,@ApiParam(name = "userId",value = "对应用户基本信息ID") @PathVariable("userId") Integer userId) {
        service.insert(workExperience, userId);
        return JsonResult.success();
    }

    @ApiOperation(value = "根据ID删除多条记录")
    @RequestMapping(value = "/delete/{ids}", method = RequestMethod.DELETE)
    public JsonResult delete(@PathVariable("ids") Integer[] ids) {
        service.removeByIds(ids);
        return JsonResult.success();
    }

    @ApiOperation(value = "根据一条ID修改记录")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public JsonResult<Object> update(@Valid WorkExperience workExperience) {
        service.updateById(workExperience);
        return JsonResult.success();
    }

    @ApiOperation(value = "关联查询登录 ID 的所有注册信息")
    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    public JsonResult<List<WorkExperience>> selectAll() {
        return JsonResult.success(mapper.selectAll());
    }

    @ApiOperation(value = "根据ID查询一条关联信息")
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    public JsonResult<WorkExperience> selectById(Integer id) {
        return JsonResult.success(service.selectById(id));
    }

}
